package com.newland.zxy.config;

import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author : zhangxuyuan
 * @Project: springcloudoauth2
 * @Package com.newland.zxy.config
 * @date Date : 2021年02月05日 14:18
 *
 *
 * 自定义token转换器
 */
@Component
public class MyAccessTokenConverter extends DefaultAccessTokenConverter {

    @Override
    public Map<String, ?> convertAccessToken
            (OAuth2AccessToken token, OAuth2Authentication authentication) {

        Map<String,Object>map =
                (Map<String, Object>)super.convertAccessToken(token,authentication);
        map.put("myattr","zxy");

        System.out.println("1"+authentication.getCredentials());
        System.out.println("2"+authentication.getPrincipal());
        System.out.println("3"+authentication.getDetails());
        System.out.println("4"+authentication.getName());
        System.out.println("5"+authentication.getUserAuthentication());
        return map;
    }
}
